package com.dodo.blog.ui.component.container;

import com.dodo.blog.ui.ajax.FormGetAjaxRequestHandler;
import com.dodo.blog.ui.ajax.FormPostAjaxRequestHandler;

/**
 * @author <a href="mailto:pohorelec@comvai.com">Jozef Pohorelec</a>
 */
public class Form
        extends Container
{
    private static final long serialVersionUID = 1L;

    public enum Method
    {
        POST,
        GET
    }

    public Form( String action )
    {
        super( Tag.FORM );

        setMethod( Method.POST );
        setAttribute( Attribute.ACTION, action );
    }

    public Form( String id, Class model )
    {
        super( Tag.FORM );
        setId( id );

        setMethod( Method.POST );
        setAttribute( Attribute.ACTION, getRequest().getRequestURI() );
        setAttribute( Attribute.MODEL, model.getName() );
        setAttribute( "gh", FormGetAjaxRequestHandler.class.getName() );
        setAttribute( "ph", FormPostAjaxRequestHandler.class.getName() );
    }

    public void setMethod( Method method )
    {
        setAttribute( Attribute.METHOD, method.name() );
    }
}